home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / C / Mesa / src / ddsample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  19.9 KB  |  758 lines

  1. /* $Id: ddsample.c,v 1.3 1996/11/13 03:52:12 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.0
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: ddsample.c,v $
  26.  * Revision 1.3  1996/11/13 03:52:12  brianp
  27.  * updated comments
  28.  *
  29.  * Revision 1.2  1996/09/15 14:30:27  brianp
  30.  * updated for new GLframebuffer and GLvisual datatypes and functions
  31.  *
  32.  * Revision 1.1  1996/09/13 01:38:16  brianp
  33.  * Initial revision
  34.  *
  35.  */
  36.  
  37.  
  38.  
  39. /*
  40.  * This is a sample template for writing new Mesa device drivers.
  41.  * You'll have to rewrite all the pseudo code below.
  42.  *
  43.  * Let's say you're interfacing Mesa to a window/operating system
  44.  * called FOO.  Replace all occurances of FOOMesa with the real name
  45.  * you select for your interface  (i.e. XMesa, WMesa, AmigaMesa).
  46.  *
  47.  * You'll have to design an API for clients to use, defined in a
  48.  * header called Mesa/include/GL/FooMesa.h  Use the sample as an
  49.  * example.  The API should at least have functions for creating
  50.  * rendering contexts, binding rendering contexts to windows/frame
  51.  * buffers, etc.
  52.  * 
  53.  * Next, you'll have to write implementations for the device driver
  54.  * functions described in dd.h
  55.  *
  56.  * Note that you'll usually have to flip Y coordinates since Mesa's
  57.  * window coordinates start at the bottom and increase upward.  Most
  58.  * window system's Y-axis increases downward
  59.  *
  60.  * Functions marked OPTIONAL may be completely omitted by your driver.
  61.  *
  62.  * Your Makefile should compile this module along with the rest of
  63.  * the core Mesa library.
  64.  */
  65.  
  66.  
  67. #include <stdlib.h>
  68. #include "GL/FooMesa.h"
  69. #include "context.h"
  70. #include "types.h"
  71. #include "vb.h"
  72.  
  73.  
  74.  
  75. /*
  76.  * This struct describes the attributes (number of channels, video mode,
  77.  * bits per pixel, etc) for a drawable (window, screen, or frame buffer).
  78.  */
  79. struct foo_mesa_visual {
  80.    GLvisual *gl_visual;
  81.    GLboolean db_flag;        /* double buffered? */
  82.    GLboolean rgb_flag;        /* RGB mode? */
  83.    GLuint depth;        /* bits per pixel (1, 8, 24, etc) */
  84. };
  85.  
  86.  
  87. /*
  88.  * This struct is a wrapper for your system's notion of a window or
  89.  * frame buffer.  It's needed because most window systems don't have
  90.  * any notion of the Z buffers, stencil buffers, etc needed by Mesa.
  91.  */
  92. struct foo_mesa_buffer {
  93.    GLframebuffer *gl_buffer;    /* The depth, stencil, accum, etc buffers */
  94.    WindowType *the_window;    /* your window handle, etc */
  95. };
  96.  
  97.  
  98.  
  99. /*
  100.  * This struct contains all device-driver state information.  Think of it
  101.  * as an extension of the core GLcontext from types.h.
  102.  */
  103. struct foo_mesa_context {
  104.    GLcontext *gl_ctx;        /* the core library context */
  105.    FooMesaVisual visual;
  106.    FooMesaBuffer buffer;
  107.    unsigned long pixel;        /* current color index or RGBA pixel value */
  108.    unsigned long clearpixel;    /* pixel for clearing the color buffers */
  109.    /* etc... */
  110. };
  111.  
  112.  
  113.  
  114.  
  115. /**********************************************************************/
  116. /*****              Miscellaneous device driver funcs             *****/
  117. /**********************************************************************/
  118.  
  119.  
  120. static void finish( GLcontext *ctx )
  121. {
  122.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  123.    /* OPTIONAL FUNCTION: implements glFinish if possible */
  124. }
  125.  
  126.  
  127.  
  128. static void flush( GLcontext *ctx )
  129. {
  130.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  131.    /* OPTIONAL FUNCTION: implements glFlush if possible */
  132. }
  133.  
  134.  
  135.  
  136. static void clear_index( GLcontext *ctx, GLuint index )
  137. {
  138.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  139.    /* implement glClearIndex */
  140.    /* usually just save the color index value in the foo struct */
  141. }
  142.  
  143.  
  144.  
  145. static void clear_color( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  146. {
  147.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  148.    /* implement glClearColor */
  149.    /* color components are floats in [0,1] */
  150.    /* usually just save the value in the foo struct */
  151. }
  152.  
  153.  
  154.  
  155. static void clear( GLcontext *ctx,
  156.            GLboolean all, GLint x, GLint y, GLint width, GLint height )
  157. {
  158.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  159. /*
  160.  * Clear the specified region of the current color buffer using the clear
  161.  * color or index as specified by one of the two functions above.
  162.  * If all==GL_TRUE, clear whole buffer, else just clear region defined
  163.  * by x,y,width,height
  164.  */
  165. }
  166.  
  167.  
  168.  
  169. static void set_index( GLcontext *ctx, GLuint index )
  170. {
  171.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  172.    /* Set the current color index. */
  173. }
  174.  
  175.  
  176.  
  177. static void set_color( GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  178. {
  179.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  180.    /* Set the current RGBA color. */
  181.    /* r is in [0,ctx->Visual->RedScale]   */
  182.    /* g is in [0,ctx->Visual->GreenScale] */
  183.    /* b is in [0,ctx->Visual->BlueScale]  */
  184.    /* a is in [0,ctx->Visual->AlphaScale] */
  185. }
  186.  
  187.  
  188.  
  189. static GLboolean index_mask( GLcontext *ctx, GLuint mask )
  190. {
  191.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  192.    /* OPTIONAL FUNCTION: implement glIndexMask if possible, else
  193.     * return GL_FALSE
  194.     */
  195. }
  196.  
  197.  
  198.  
  199. static GLboolean color_mask( GLcontext *ctx, 
  200.                              GLboolean rmask, GLboolean gmask,
  201.                              GLboolean bmask, GLboolean amask)
  202. {
  203.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  204.    /* OPTIONAL FUNCTION: implement glColorMask if possible, else
  205.     * return GL_FALSE
  206.     */
  207. }
  208.  
  209.  
  210.  
  211. static GLboolean logicop( GLcontext *ctx, GLenum op )
  212. {
  213.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  214.    /*
  215.     * OPTIONAL FUNCTION: 
  216.     * Implements glLogicOp if possible.  Return GL_TRUE if the device driver
  217.     * can perform the operation, otherwise return GL_FALSE.  If GL_FALSE
  218.     * is returned, the logic op will be done in software by Mesa.
  219.     */
  220. }
  221.  
  222.  
  223. static void dither( GLcontext *ctx, GLboolean enable )
  224. {
  225.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  226.    /* OPTIONAL FUNCTION: enable/disable dithering if applicable */
  227. }
  228.  
  229.  
  230.  
  231. static GLboolean set_buffer( GLcontext *ctx, GLenum mode )
  232. {
  233.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  234.    /* set the current drawing/reading buffer, return GL_TRUE or GL_FALSE */
  235.    /* for success/failure */
  236.    setup_DD_pointers( ctx );
  237. }
  238.  
  239.  
  240.  
  241. static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
  242. {
  243.    struct foo_mesa_context *foo = (struct foo_mesa_context *) ctx->DriverCtx;
  244.    /* return the width and height of the current buffer */
  245.    /* if anything special has to been done when the buffer/window is */
  246.    /* resized, do it now */
  247. }
  248.  
  249.  
  250.  
  251. /**********************************************************************/
  252. /*****           Accelerated point, line, triangle rendering      *****/
  253. /**********************************************************************/
  254.  
  255.  
  256. /* There may several functions like this, for different screen modes, etc */
  257. static void fast_points_function( GLcontext *ctx, GLuint first, GLuint last )
  258. {
  259.    struct vertex_buffer *VB = ctx->VB;
  260.  
  261.    /* Render a number of points by some hardware/OS accerated method */
  262.    if (VB->MonoColor) {
  263.       /* draw all points using the current color (set_color) */
  264.       for (i=first;i<=last;i++) {
  265.          if (VB->Unclipped[i]) {
  266.             /* compute window coordinate */
  267.             int x, y;
  268.             x =       (GLint) VB->Win[i][0];
  269.             y = FLIP( (GLint) VB->Win[i][1] );
  270.             PLOT_PIXEL( x, y, currentcolor );
  271.          }
  272.       }
  273.    }
  274.    else {
  275.       /* each point is a different color */
  276.       for (i=first;i<=last;i++) {
  277.          if (VB->Unclipped[i]) {
  278.             int x, y;
  279.             x =       (GLint) VB->Win[i][0];
  280.             y = FLIP( (GLint) VB->Win[i][1] );
  281.             PLOT_PIXEL( x, y, VB->Color[i] );
  282.          }
  283.       }
  284.    }
  285. }
  286.  
  287.  
  288.  
  289.  
  290. /* There may several functions like this, for different screen modes, etc */
  291. static void fast_line_function( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv )
  292. {
  293.    /* Render a line by some hardware/OS accerated method */
  294.    struct vertex_buffer *VB = ctx->VB;
  295.    int x0, y0, x1, y1;
  296.    unsigned long pixel;
  297.  
  298.    if (VB->MonoColor) {
  299.       pixel = current color;
  300.    }
  301.    else {
  302.       pixel = VB->Color[pv];
  303.    }
  304.  
  305.    x0 =       (int) VB->Win[v0][0];
  306.    y0 = FLIP( (int) VB->Win[v0][1] );
  307.    x1 =       (int) VB->Win[v1][0];
  308.    y1 = FLIP( (int) VB->Win[v1][1] );
  309.  
  310.    DRAW_LINE( x0,y0, x1,y1, pixel );
  311. }
  312.  
  313.  
  314.  
  315.  
  316. /* There may several functions like this, for different screen modes, etc */
  317. static void fast_triangle_function( GLcontext *ctx, GLuint v0,
  318.                                     GLuint v1, GLuint v2, GLuint pv )
  319. {
  320.    /* Render a triangle by some hardware/OS accerated method */
  321.    struct vertex_buffer *VB = ctx->VB;
  322.    int i;
  323.  
  324.    if (VB->MonoColor) {
  325.       pixel = current color or index;
  326.    }
  327.    else {
  328.       pixel = VB->Color[pv] or VB->Index[pv];
  329.    }
  330.  
  331.    DRAW_TRIANGLE( v0, v1, v2 );
  332. }
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339. /**********************************************************************/
  340. /*****            Write spans of pixels                           *****/
  341. /**********************************************************************/
  342.  
  343.  
  344. static void write_index_span( GLcontext *ctx,
  345.                               GLuint n, GLint x, GLint y,
  346.                               const GLuint index[],
  347.                               const GLubyte mask[] )
  348. {
  349.    int i;
  350.    for (i=0;i<n;i++) {
  351.       if (mask[i]) {
  352.          /* draw pixel (x[i],y[i]) using index[i] */
  353.       }
  354.    }
  355. }
  356.  
  357.  
  358.  
  359. static void write_monoindex_span( GLcontext *ctx,
  360.                                   GLuint n,GLint x,GLint y,const GLubyte mask[] )
  361. {
  362.    int i;
  363.    for (i=0;i<n;i++) {
  364.       if (mask[i]) {
  365.          /* draw pixel (x[i],y[i]) using current color index */
  366.       }
  367.    }
  368. }
  369.  
  370.  
  371.  
  372. static void write_color_span( GLcontext *ctx, 
  373.                               GLuint n, GLint x, GLint y,
  374.                               const GLubyte red[], const GLubyte green[],
  375.                               const GLubyte blue[], const GLubyte alpha[],
  376.                               const GLubyte mask[] )
  377. {
  378.    int i;
  379.    y=FLIP(y);
  380.    if (mask) {
  381.       /* draw some pixels */
  382.       for (i=0; i<n; i++, x++) {
  383.          if (mask[i]) {
  384.             /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  385.          }
  386.       }
  387.    }
  388.    else {
  389.       /* draw all pixels */
  390.       for (i=0; i<n; i++, x++) {
  391.          /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  392.       }
  393.    }
  394. }
  395.  
  396.  
  397.  
  398. static void write_monocolor_span( GLcontext *ctx,
  399.                                   GLuint n, GLint x, GLint y,
  400.                                   const GLubyte mask[])
  401. {
  402.    int i;
  403.    y=FLIP(y);
  404.    for (i=0; i<n; i++, x++) {
  405.       if (mask[i]) {
  406.          plot pixel (x,y) using current color
  407.       }
  408.    }
  409. }
  410.  
  411.  
  412.  
  413. /**********************************************************************/
  414. /*****                 Read spans of pixels                       *****/
  415. /**********************************************************************/
  416.  
  417.  
  418. static void read_index_span( GLcontext *ctx,
  419.                              GLuint n, GLint x, GLint y, GLuint index[])
  420. {
  421.    int i;
  422.    for (i=0; i<n; i++) {
  423.       index[i] = read_pixel(x[i],y[i]);
  424.    }
  425. }
  426.  
  427.  
  428.  
  429. static void read_color_span( GLcontext *ctx,
  430.                              GLuint n, GLint x, GLint y,
  431.                              GLubyte red[], GLubyte green[],
  432.                              GLubyte blue[], GLubyte alpha[] )
  433. {
  434.    int i;
  435.    for (i=0; i<n; i++, x++) {
  436.       red[i] = read_red( x, y );
  437.       green[i] = read_green( x, y );
  438.       /* etc */
  439.    }
  440. }
  441.  
  442.  
  443.  
  444. /**********************************************************************/
  445. /*****              Write arrays of pixels                        *****/
  446. /**********************************************************************/
  447.  
  448.  
  449. static void write_index_pixels( GLcontext *ctx,
  450.                                 GLuint n, const GLint x[], const GLint y[],
  451.                                 const GLuint index[], const GLubyte mask[] )
  452. {
  453.    int i;
  454.    for (i=0; i<n; i++) {
  455.       if (mask[i]) {
  456.          plot pixel x[i], y[i] using index[i]
  457.       }
  458.    }
  459. }
  460.  
  461.  
  462.  
  463. static void write_monoindex_pixels( GLcontext *ctx,
  464.                                     GLuint n,
  465.                                     const GLint x[], const GLint y[],
  466.                                     const GLubyte mask[] )
  467. {
  468.    int i;
  469.    for (i=0; i<n; i++) {
  470.       if (mask[i]) {
  471.          write pixel x[i], y[i] using current index
  472.       }
  473.    }
  474. }
  475.  
  476.  
  477.  
  478. static void write_color_pixels( GLcontext *ctx,
  479.                                 GLuint n, const GLint x[], const GLint y[],
  480.                                 const GLubyte r[], const GLubyte g[],
  481.                                 const GLubyte b[], const GLubyte a[],
  482.                                 const GLubyte mask[] )
  483. {
  484.    int i;
  485.    for (i=0; i<n; i++) {
  486.       if (mask[i]) {
  487.          write pixel x[i], y[i] using red[i],green[i],blue[i],alpha[i]
  488.       }
  489.    }
  490. }
  491.  
  492.  
  493.  
  494. static void write_monocolor_pixels( GLcontext *ctx,
  495.                                     GLuint n,
  496.                                     const GLint x[], const GLint y[],
  497.                                     const GLubyte mask[] )
  498. {
  499.    int i;
  500.    for (i=0; i<n; i++) {
  501.       if (mask[i]) {
  502.          write pixel x[i], y[i] using current color
  503.       }
  504.    }
  505. }
  506.  
  507.  
  508.  
  509.  
  510. /**********************************************************************/
  511. /*****                   Read arrays of pixels                    *****/
  512. /**********************************************************************/
  513.  
  514. /* Read an array of color index pixels. */
  515. static void read_index_pixels( GLcontext *ctx,
  516.                                GLuint n, const GLint x[], const GLint y[],
  517.                                GLuint indx[], const GLubyte mask[] )
  518. {
  519.   int i;
  520.   for (i=0; i<n; i++) {
  521.      if (mask[i]) {
  522.         index[i] = read_pixel( x[i], y[i] );
  523.      }
  524.   }
  525. }
  526.  
  527.  
  528.  
  529. static void read_color_pixels( GLcontext *ctx,
  530.                                GLuint n, const GLint x[], const GLint y[],
  531.                                GLubyte red[], GLubyte green[],
  532.                                GLubyte blue[], GLubyte alpha[],
  533.                                const GLubyte mask[] )
  534. {
  535.    int i;
  536.    for (i=0; i<n; i++) {
  537.       if (mask[i]) {
  538.          red[i] = read_red( x[i], y[i] );
  539.          green[i] = read_green( x[i], y[i] );
  540.          /* etc */
  541.       }
  542.    }
  543. }
  544.  
  545.  
  546.  
  547.  
  548. /**********************************************************************/
  549. /**********************************************************************/
  550.  
  551.  
  552. static void setup_DD_pointers( GLcontext *ctx )
  553. {
  554.    /* Initialize all the pointers in the DD struct.  Do this whenever */
  555.    /* a new context is made current or we change buffers via set_buffer! */
  556.  
  557.    ctx->Driver.UpdateState = setup_DD_pointers;
  558.  
  559.    ctx->Driver.ClearIndex = clear_index;
  560.    ctx->Driver.ClearColor = clear_color;
  561.    ctx->Driver.Clear = clear;
  562.  
  563.    ctx->Driver.Index = set_index;
  564.    ctx->Driver.Color = set_color;
  565.  
  566.    ctx->Driver.SetBuffer = set_buffer;
  567.    ctx->Driver.GetBufferSize = get_buffer_size;
  568.  
  569.    ctx->Driver.PointsFunc = fast_points_function;
  570.    ctx->Driver.LineFunc = fast_line_function;
  571.    ctx->Driver.TriangleFunc = fast_triangle_function;
  572.  
  573.    /* Pixel/span writing functions: */
  574.    ctx->Driver.WriteColorSpan       = write_color_span;
  575.    ctx->Driver.WriteMonocolorSpan   = write_monocolor_span;
  576.    ctx->Driver.WriteColorPixels     = write_color_pixels;
  577.    ctx->Driver.WriteMonocolorPixels = write_monocolor_pixels;
  578.    ctx->Driver.WriteIndexSpan       = write_index_span;
  579.    ctx->Driver.WriteMonoindexSpan   = write_monoindex_span;
  580.    ctx->Driver.WriteIndexPixels     = write_index_pixels;
  581.    ctx->Driver.WriteMonoindexPixels = write_monoindex_pixels;
  582.  
  583.    /* Pixel/span reading functions: */
  584.    ctx->Driver.ReadIndexSpan = read_index_span;
  585.    ctx->Driver.ReadColorSpan = read_color_span;
  586.    ctx->Driver.ReadIndexPixels = read_index_pixels;
  587.    ctx->Driver.ReadColorPixels = read_color_pixels;
  588.  
  589.  
  590.    /*
  591.     * OPTIONAL FUNCTIONS:  these may be left uninitialized if the device
  592.     * driver can't/needn't implement them.
  593.     */
  594. #if 0
  595.    ctx->Driver.Finish = finish;
  596.    ctx->Driver.Flush = flush;
  597.    ctx->Driver.IndexMask = index_mask;
  598.    ctx->Driver.ColorMask = color_mask;
  599.    ctx->Driver.LogicOp = logicop;
  600.    ctx->Driver.Dither = dither;
  601. #endif
  602. }
  603.  
  604.  
  605.  
  606. /**********************************************************************/
  607. /*****               FOO/Mesa API Functions                       *****/
  608. /**********************************************************************/
  609.  
  610.  
  611.  
  612. /*
  613.  * The exact arguments to this function will depend on your window system
  614.  */
  615. FooMesaVisual FooMesaCreateVisual( GLboolean rgb_mode, GLboolean db_flag,
  616.                                    /* etc... */ )
  617. {
  618.    FooMesaVisual v;
  619.    GLfloat redscale, greenscale, bluescale, alphascale;
  620.  
  621.    v = (FooMesaVisual) calloc( 1, sizeof(struct foo_mesa_visual) );
  622.    if (!v) {
  623.       return NULL;
  624.    }
  625.  
  626.    if (rgb_mode) {
  627.       /* RGB(A) mode */
  628.       redscale = ??;
  629.       greedscale = ??;
  630.       bluescale = ??;
  631.       alphascale = ??;
  632.       index_bits = 0;
  633.    }
  634.    else {
  635.       /* color index mode */
  636.       redscale = 0.0;
  637.       greedscale = 0.0;
  638.       bluescale = 0.0;
  639.       alphascale = 0.0;
  640.       index_bits = ??;
  641.    }
  642.  
  643.    /* Create core visual */
  644.    v->gl_visual = gl_create_visual( rgb_mode, 
  645.                                     alpha_flag,
  646.                                     db_flag,
  647.                                     depth_size,
  648.                                     stencil_size,
  649.                                     accum_size,
  650.                                     redscale, greenscale,
  651.                                     bluescale, alphascale,
  652.                                     index_bits );
  653.  
  654.    return v;
  655. }
  656.  
  657.  
  658.  
  659. void FooMesaDestroyVisual( FooMesaVisual v )
  660. {
  661.    gl_destroy_visual( v->gl_visual );
  662.    free( v );
  663. }
  664.  
  665.  
  666.  
  667.  
  668. FooMesaBuffer FooMesaCreateBuffer( FooMesaVisual visual,
  669.                                    int /* your window id */ )
  670. {
  671.    FooMesaBuffer b;
  672.  
  673.    b = (FooMesaBuffer) calloc( 1, sizeof(struct foo_mesa_buffer) );
  674.    if (!b) {
  675.       return NULL;
  676.    }
  677.  
  678.    b->gl_buffer = gl_create_buffer( visual->gl_visual, windowid, 0, 0 );
  679.  
  680.    /* other stuff */
  681.  
  682.    return b;
  683. }
  684.  
  685.  
  686.  
  687. void FooMesaDestroyBuffer( FooMesaBuffer b )
  688. {
  689.    gl_destroy_buffer( b->gl_buffer );
  690.    free( b );
  691. }
  692.  
  693.  
  694.  
  695.  
  696. FooMesaContext FooMesaCreateContext( FooMesaVisual visual,
  697.                                      FooMesaContext share )
  698. {
  699.    FooMesaContext c;
  700.  
  701.    c = (FooMesaContext) calloc( 1, sizeof(struct foo_mesa_context) );
  702.    if (!c) {
  703.       return NULL;
  704.    }
  705.  
  706.    c->gl_ctx = gl_create_context( visual->gl_visual,
  707.                                   share ? share->gl_ctx : NULL,
  708.                                   (void *) c );
  709.  
  710.  
  711.    /* you probably have to do a bunch of other initializations here. */
  712.  
  713.    return c;
  714. }
  715.  
  716.  
  717.  
  718. void FooMesaDestroyContext( FooMesaContext c )
  719. {
  720.    gl_destroy_context( c->gl_ctx );
  721.    free( c );
  722. }
  723.  
  724.  
  725.  
  726. /*
  727.  * Make the specified context the current one */
  728.  * Might also want to specify the window/drawable here, like for GLX.
  729.  */
  730. void FooMesaMakeCurrent( FooMesaContext c, FooMesaBuffer b )
  731. {
  732.    if (c && b) {
  733.       gl_make_current( c->gl_ctx, b->gl_buffer );
  734.       Current_context = c;
  735.       if (c->gl_ctx->Viewport.Width==0) {
  736.          /* initialize viewport to window size */
  737.          gl_Viewport( c->gl_ctx, 0, 0, c->width, c->height );
  738.       }
  739.    }
  740.    else {
  741.       /* Detach */
  742.       gl_make_current( NULL, NULL );
  743.       Current = NULL;
  744.    }
  745. }
  746.  
  747.  
  748.  
  749. void FooMesaSwapBuffers( FooMesaBuffer b )
  750. {
  751.    /* copy/swap back buffer to front if applicable */
  752. }
  753.  
  754.  
  755.  
  756. /* you may need to add other FOO/Mesa functions too... */
  757.  
  758.